#ifndef __OS_SEMPHORE_H
#define __OS_SEMPHORE_H


#include "os_config.h"
#include "os_core.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef volatile struct os_semaphore OS_SEM_MEMORY
{
    uint16_t                          count;     // Semaphore count
    uint16_t                      max_count;     // Maximum count
}os_semaphore_st;

#define OS_SEMAPHORE_INIT(init_value, max_count)  {init_value, max_count}
#define os_semaphore_take(p_semaphore,timeout_ms,ret) OS_TASK_WAIT_TIMEOUT(os_semaphore_try_take(p_semaphore) == 0, timeout_ms,ret)
#define os_semaphore_give_from_isr(p_semaphore)   os_semaphore_give(p_semaphore)

extern int os_semaphore_init(os_semaphore_st  * const semaphore, uint16_t init_value,uint16_t max_count);
extern int os_semaphore_give(os_semaphore_st  * const semaphore);
extern int os_semaphore_try_take(os_semaphore_st  * const semaphore);


#ifdef __cplusplus
}
#endif
#endif
